//引入模块
const express = require('express');
//中间件cookie
const cookie = require('cookie-parser');
//body中间件
const bodyParser = require('body-parser');
//path模块
const path = require('path');

//创建express框架应用模块
const app = express();

//模板引擎设置
//__dirname  : 常量，当前项目路径   localhost：端口
app.set('views', path.join(__dirname , 'templates'));
app.set('view engine' , 'ejs');
// console.log(__dirname)
//解析中间件
app.use(bodyParser.urlencoded({extended:false}));

app.use(bodyParser.json());   //对象字符串  应用body中间件
// console.log(bodyParser)
// console.log(cookie)

app.use(cookie());    //应用cookie中间件

const moment = require('moment');
app.locals.moment = moment;

//加载静态页面
app.use(express.json());

app.use(express.urlencoded({extended:false}));
app.use(express.static( path.join( __dirname , 'public') ));

//导入业务模块
const login = require('./routes/login');
const home = require('./routes/home');
const logout = require('./routes/logout');
const homeTeach = require('./routes/home_teach');
const chenck = require('./routes/chenck');
const selScores = require('./routes/sel_scores');
const selList = require('./routes/sel_list');
const addList = require('./routes/add_list');
const addScores = require('./routes/add_scores');
const stuUpdate = require('./routes/stu_update');
const stuDelete = require('./routes/stu_delete');



//
app.use('/', login);
app.use('/home', home);
app.use('/home_teach', homeTeach);
app.use('/logout', logout);
app.use('/chenck', chenck);
app.use('/sel_scores', selScores);
app.use('/sel_list', selList);
app.use('/add_list', addList);
app.use('/add_scores', addScores);
app.use('/stu_update',stuUpdate);
app.use('/stu_delete',stuDelete);


//开启监听
app.listen(8080 , ()=>{
    console.log('开启监听')
})